# -*- coding: utf-8 -*-
"""
@Time    : 2021/10/9 1:58
@Author  : Leibuyun
@File    : 1.10 删除序列相同的元素并保持顺序.py
"""


# 序列中的元素为hashable
def dedupe(items):
    s = set()
    for item in items:
        if item not in s:
            yield item
            s.add(item)


# 如果序列中的元素能转换成hashable类型
def dedupe2(items, key=None):
    seen = set()
    for item in items:
        val = item if key is None else key(item)
        if val not in seen:
            yield item
            seen.add(val)


if __name__ == '__main__':
    a = [1, 5, 2, 1, 9, 1, 5, 10]
    a = list(dedupe(a))
    print(a)
